﻿<nav class="navbar navbar-inverse navbar-fixed-top" role="navigation">
    <!-- Brand and toggle get grouped for better mobile display -->
    <div class="navbar-header">
        <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-ex1-collapse">
            <span class="sr-only">Toggle navigation</span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
        </button>
        <a class="navbar-brand" href="@Url.Action("Index", "Home")">SIIA</a>
    </div>

    @if (Request.IsAuthenticated)
    {
        <!-- Collect the nav links, forms, and other content for toggling -->
        <div class="collapse navbar-collapse navbar-ex1-collapse">
            <ul class="nav navbar-nav">
                @{ var currentController = ViewContext.RouteData.Values["controller"].ToString().ToLower(); }

                <li class="@(currentController.Equals("escenas") ? "active" : "")"><a href="@Url.Action("Index", "Escenas")"><span class="glyphicon glyphicon-eye-open"></span>Escenas</a></li>
                <li class="@(currentController.Equals("ambientes") ? "active" : "")"><a href="@Url.Action("Index", "Ambientes")"><span class="glyphicon glyphicon-picture"></span>Ambientes</a></li>
                <li class="@(currentController.Equals("historial") ? "active" : "")"><a href="@Url.Action("Index", "Historial")"><span class="glyphicon glyphicon-floppy-disk"></span>Historial</a></li>

                <li class="dropdown @(currentController.Equals("aparatos") ||
                                      currentController.Equals("modulos") ||
                                      currentController.Equals("zonas") ||
                                      currentController.Equals("tipoaparatos") ? "active" : "")">
                    <a href="#" class="dropdown-toggle" data-toggle="dropdown"><span class="glyphicon glyphicon-cog"></span>Administración <b class="caret"></b></a>
                    <ul class="dropdown-menu">
                        <li><a href="@Url.Action("Index", "Aparatos")">Aparatos</a></li>
                        <li><a href="@Url.Action("Index", "Modulos")">Modulos</a></li>
                        <li><a href="@Url.Action("Index", "Zonas")">Zonas</a></li>
                        <li><a href="@Url.Action("Index", "TipoAparatos")">Tipos de Aparatos</a></li>
                    </ul>
                </li>
            </ul>
            <ul class="nav navbar-nav pull-right">
                <!-- Login -->
                <li class="dropdown">
                    @Html.Partial("_LoginPartial")
                </li>
                <li>
                    <span style="font-size: 32px">|</span>
                </li>
                <!-- Hora -->
                <li>
                    <p class="navbar-text" id="clock"></p>
                </li>
            </ul>
        </div>
    
        
    }
    else
    {
        <div>
        <ul class="nav navbar-nav pull-right">
                <!-- Login -->
                <li class="dropdown">
                    @Html.Partial("_LoginPartial")
                </li>
                <li>
                    <span style="font-size: 32px">|</span>
                </li>
                <!-- Hora -->
                <li>
                    <p class="navbar-text" id="clock"></p>
                </li>
            </ul>
        </div>
    }

</nav>

<script>
    $(document).ready(function () {
        $('#dropdown-login').find('form').click(function (e) {
            e.stopPropagation();
        });

        actualizarFechaYHora();
        setInterval('actualizarFechaYHora()', 1000);
    });

    function actualizarFechaYHora() {
        var currentTime = new Date();
        var currentHours = currentTime.getHours();
        var currentMinutes = currentTime.getMinutes();
        var currentSeconds = currentTime.getSeconds();

        currentMinutes = (currentMinutes < 10 ? "0" : "") + currentMinutes;
        currentSeconds = (currentSeconds < 10 ? "0" : "") + currentSeconds;
        currentHours = (currentHours < 10 ? "0" : "") + currentHours;
        var currentTimeString = currentHours + ":" + currentMinutes + ":" + currentSeconds;

        var monthNames = ["Ene", "Feb", "Mar", "Abr", "May", "Jun", "Jul", "Ago", "Sep", "Oct", "Nov", "Dic"];
        var dayNames = ["Dom", "Lun", "Mar", "Mie", "Jue", "Vie", "Sab"];
        var currentDateString = dayNames[currentTime.getDay()] + " " + currentTime.getDate() + ' ' + monthNames[currentTime.getMonth()];

        $("#clock").html('<span class="glyphicon glyphicon-time"></span> ' + currentTimeString);
        //$("#date").html(currentDateString);
    }
</script>
